const axios = require('axios');
const CryptoJS = require('crypto-js');
 async function fetchData() {
  try {
    // Step 1: Get the SecretKey
    const response1 = await axios.get('');
   
    const key = response1.data.body.SecretKey;
     // Step 2: Generate usercode using AES encryption
    const usercode = aes('heqinghang', key);
     // Step 3: Get JSESSIONID
    const response2 = await axios.get(`usercode=${usercode}`);
  
    const JSESSIONID = response2.data.body.JSESSIONID;
    console.error('JSESSIONID=', JSESSIONID);
     // Step 4: Use JSESSIONID to fetch task information
    const response3 = await axios.get('', {
      headers: {
        Cookie: `JSESSIONID=${JSESSIONID}`,
      },
    });
     // Process the task information response
    console.log(response3.data);
  } catch (error) {
    console.error('Error:', error.message);
  }
}
 // AES encryption function
function aes(word, keyStr) {
  const key = CryptoJS.enc.Utf8.parse(keyStr);
  const srcs = CryptoJS.enc.Utf8.parse(word);
  const encrypted = CryptoJS.AES.encrypt(srcs, key, { mode: CryptoJS.mode.ECB, padding: CryptoJS.pad.Pkcs7, });
  return encrypted.toString();
}
 // Call the fetchData function
fetchData();